import together from '@/common/together.js';
export default {
	data() {
		return {
			loading: false,
			// 保存从上个页面传来的公司id
			companyCid: null,

			// 保存公司信息
			companyMsg: {
				"companyName": null,
				"companyLegalPersonName": null,
				"companyIndustry": null,
				"companyRegCapital": null,
				"companyType": null,
				"companyUpdateTime": null,
				"companyRegLocation": null,
				"companyRegInstitute": null
			},
			companyName: null,
			baseList: [{

					title: '开标记录',
					class: 'iconfont iconicon_xinyong_xianxing_jijin-190'
				},
				{
					title: '变更记录',
					class: 'iconfont iconchange1'
				},
				{

					title: '主要人员',
					class: 'iconfont iconzhuyaorenyuan'
				}, {
					title: '注册人员',
					class: 'iconfont iconrenyuan-'
				},
				{
					title: '企业资质',
					class: 'iconfont iconzizhirenzheng'
				},
				{
					title: '企业业绩',
					class: 'iconfont iconyejifenxi'
				},
				{
					title: '税务等级',
					class: 'iconfont iconshuiwu1'
				},
				{
					title: '对外投资',
					class: 'iconfont iconicon_xinyong_xianxing_jijin-116'
				}
			]
		}
	},
	// 获取从上一页面传递的参数
	onLoad(option) {
		
		// console.log("______________",option)
		// 查询该公司详情
		if (option.companyCid) {
			this.companyCid = option.companyCid
		}
		if (option.companyName) {
			this.companyName = option.companyName
		}
		this.checkCompany()
		
		setTimeout(() => {
			this.recordHistoryName(this.companyMsg.companyName)
		}, 1000)
	},
	methods: {
		// 将公司名称加入缓存
		recordHistoryName(value) {
			// 拿取缓存
			let historyName = uni.getStorageSync('historyName');

			let i = 0
			// 将搜索的关键字保存到缓存之中
			if (!historyName) {
				historyName = []

			} else {

				// 判断该内容是否重复
				for (let item of historyName) {
					if (item == value) {
						i = 1
					}
				}

			}
			if (i == 0) {
				historyName.unshift(value)

			}
			let arr = historyName
			historyName = []
			arr.forEach((item, index) => {
				if (historyName.length < 10) {
					if (item)
						historyName.push(item)
				}

			})
			uni.setStorageSync('historyName', historyName);
		},
		// 拨打电话
		callPhone(phone) {
			// console.log("phone",phone)
			if(phone){
				// #ifdef MP-WEIXIN
				uni.makePhoneCall({
					phoneNumber: phone
				});
				// #endif
				//安卓手机手动设置一个showActionSheet
				//   #ifdef APP-PLUS
				uni.showActionSheet({
					itemList: [phone, '呼叫'],
					success: function(res) {
						// console.log(res);
						if (res.tapIndex == 1) {
							uni.makePhoneCall({
								phoneNumber: phone,
							})
						}
					}
				})
				// #endif
			}else{
				this.$refs.uToast.show({
					message: '该企业暂时还未上传电话',
					type: 'success'
				})
			}
			
		},
		// 信息提示
		showTip(data) {

			// 判断字符长度，长度大于7，用show，小于用alter
			if (data.length >= 7) {

				this.$refs.uToast.show({
					message: data,
					type: 'success'
				})
			} else {

				this.$alert(data);
			}

		},
		// 跳转至开标记录页面
		gridClick(index) {
			if (index == 0) {
				uni.navigateTo({
					url: `/pagesFind/detailenterprise/bidOpeningRecord/bidOpeningRecord?companyCid=${this.companyCid}`
				})
			} else if (index == 1) {
				// 跳转至变更记录页面
				uni.navigateTo({
					url: `/pagesFind/detailenterprise/changeRecord/changeRecord?companyCid=${this.companyCid}`
				})
			} else {

				// 跳转至主要人员页面
				uni.navigateTo({
					url: `/pagesFind/detailenterprise/mainPerson/mainPerson?companyCid=${this.companyCid}&&index=${index}`
				})
			}
		},
		// 查询公司详情
		checkCompany() {
			let param = {}
			if (this.companyCid) {
				param.companyCid = this.companyCid
			}
			if (this.companyName) {
				param.companyName = this.companyName
			}
			this.loading = true
			this.$app.request({
				url: this.$baseApp.api.dicData.company,
				data: param,
				method: 'GET',
				dataType: 'json',
				success: res => {

					if (res.code == 200) {
						// console.log("++++++res+++++++", res);
						if (res.data.companyBaseInfo.length > 199) {
							res.data.companyBaseInfoCheck = false
							res.data.companyBaseInfo2 = res.data.companyBaseInfo.slice(0, 200) + '...'
							res.data.companyBaseInfoFlag = false
						} else {
							res.data.companyBaseInfoCheck = true
							res.data.companyBaseInfoFlag = true
						}
						if (res.data.companyBusinessScope.length > 199) {
							res.data.companyBusinessScopeCheck = false
							res.data.companyBusinessScope2 = res.data.companyBusinessScope.slice(0, 200) +
								'...'
							// 用来决定收起是否出现
							res.data.companyBusinessScopeFlag = false
						} else {
							res.data.companyBusinessScopeCheck = true
							res.data.companyBusinessScopeFlag = true
						}
						res.data.companyToTime = uni.$u.timeFormat(res.data.companyToTime, 'yyyy-mm-dd');

						res.data.sumMoney = (res.data.sumMoney / 10000).toFixed(1)
						res.data.maxMoney = (res.data.maxMoney / 10000).toFixed(1)
						if (res.data.companyHistoryNames) {
							res.data.companyHistoryNames = res.data.companyHistoryNames.split("$$$")
						}
						if (res.data.bidderAreaName) {
							res.data.bidderAreaName = res.data.bidderAreaName.split(",")
						}
						this.companyMsg = res.data
						// console.log("______________________________s",this.companyMsg.companyQualificationDetailsListSize)

					} else {
						// this.$alert(res.msg);
						if (res.code == 440) {
							console.log("------------440--------------")
							uni.$emit('bindVip')
							// 保存当前页面id
							uni.setStorageSync('limitId', {
								type:'company',
								id:this.companyCid
							});
							together.memberTip()
						} else {
							this.showTip(res.msg)
							setTimeout(() => {
								uni.navigateBack({
									delta: 1
								});
							}, 1000)
						}

					}
				},

				complete: res => {
					uni.stopPullDownRefresh();
					uni.hideLoading();
					this.loading = false
				}
			});
		},

		click(index) {
			// console.log("______________________________s",index)
		}
	}
}
